#include "qbcitargetinterface.h"

void QBciTargetInterface::paint(QPainter *painter) {
  painter->save();
  stylePaint(painter);
  painter->restore();

  painter->save();
  labelPaint(painter);
  painter->restore();
}

void QBciTargetInterface::labelPaint(QPainter *painter) {
  if (!ShowLabel.isEmpty()) {
    QFont headerFont;
    headerFont.setFamilies(QStringList() << "Helvetica"
                                         << "Microsoft YaHei");
    headerFont.setPixelSize(45);
    painter->setFont(headerFont);
    painter->setRenderHint(QPainter::Antialiasing);
    painter->setPen(QColor(220, 220, 220));
    int width = painter->fontMetrics().horizontalAdvance(this->ShowLabel),
        height = painter->fontMetrics().height();
    QRect textRect;
    switch (ShowLabelPos) {
    case North:
      textRect = QRect(X, Y - height, Width, height);
      break;
    case South:
      textRect = QRect(X, Y + Height, Width, height);
      break;
    case East:
      textRect = QRect(X + Width, Y, width, Height);
      break;
    case West:
      textRect = QRect(X - width, Y, width, Height);
      break;
    case NonePos:
      break;
    }
    painter->drawText(textRect, Qt::AlignCenter, this->ShowLabel);
  }
}
